/*
 *
 *      Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the pig4cloud.com developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: lengleng (wangiegie@gmail.com)
 *
 */

package com.pig4cloud.pigx.user.api.feign;

import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import com.pig4cloud.pigx.common.core.constant.ServiceNameConstants;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.user.entity.UserLogs;
import com.pig4cloud.pigx.user.vo.UserApiIpCacheVO;
import com.pig4cloud.pigx.user.vo.UserApiKeyCacheVO;
import com.pig4cloud.pigx.user.vo.UserApiKeyInfoVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author lengleng
 * @date 2018/6/22
 */
@FeignClient(contextId = "rooUserRemoteUserService", value = ServiceNameConstants.USER_SERVICE)
public interface RippleRemoteUserService {

	String API_KEY_PREFIX = "/userapikey";
	String API_IP_PREFIX = "/userapiip";

	/**
	 * 根据AccessKey查询ApiKey所有相关信息
	 */
	String GET_API_KEY_INFO = "/info";
	/**
	 * 根据AccessKey查询ApiKey信息
	 */
	String GET_API_KEY_CACHE = "/cache";
	/**
	 * 根据apiKeyId查询相关IP信息
	 */
	String GET_API_KEY_IP_CACHE = "/cache";

	/**
	 * 保存日志
	 *
	 * @param userLogs 日志实体
	 * @param from     是否内部调用
	 * @return true/false
	 */
	@PostMapping("/userlogs/saveLog")
	R<Boolean> saveLog(@RequestBody UserLogs userLogs, @RequestHeader(SecurityConstants.FROM) String from);

	/**
	 * 根据AccessKey查询ApiKey所有相关信息
	 *
	 * @param accessKey 访问密钥
	 * @param from      标注系统内调用
	 * @param token     token
	 * @return {@link R< UserApiKeyInfoVO>}
	 * @since 2022/11/9 10:53
	 */
	@GetMapping(API_KEY_PREFIX + GET_API_KEY_INFO)
	R<UserApiKeyInfoVO> getApiKeyInfo(@RequestParam("accessKey") String accessKey,
									  @RequestHeader(SecurityConstants.FROM) String from,
									  @RequestHeader(SecurityConstants.AUTHORIZATION) String token);

	/**
	 * 根据AccessKey查询信息
	 *
	 * @param accessKey 访问密钥
	 * @param from      标注系统内调用
	 * @param token     token
	 * @return {@link R< UserApiKeyCacheVO>}
	 * @since 2022/11/9 10:53
	 */
	@GetMapping(API_KEY_PREFIX + GET_API_KEY_CACHE)
	R<UserApiKeyCacheVO> getApiKeyCache(@RequestParam("accessKey") String accessKey,
										@RequestHeader(SecurityConstants.FROM) String from,
										@RequestHeader(SecurityConstants.AUTHORIZATION) String token);

	/**
	 * 根据AccessKey查询相关IP信息
	 *
	 * @param apiKeyId  apiKeyId
	 * @param accessKey 访问密钥
	 * @param from      标注系统内调用
	 * @param token     token
	 * @return {@link R< List< UserApiIpCacheVO>>}
	 * @since 2022/11/9 10:53
	 */
	@GetMapping(API_IP_PREFIX + GET_API_KEY_IP_CACHE)
	R<List<UserApiIpCacheVO>> getApiKeyIpCache(@RequestParam("apiKeyId") Long apiKeyId,
											   @RequestParam("accessKey") String accessKey,
											   @RequestHeader(SecurityConstants.FROM) String from,
											   @RequestHeader(SecurityConstants.AUTHORIZATION) String token);
}
